package com.ruoyi.web.controller.wasterTran;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.enums.RolesEnums;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wasterTran.domain.TConstructionWasteTransportationOrder;
import com.ruoyi.wasterTran.service.ITConstructionWasteTransportationOrderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 建筑垃圾联运订单信息Controller
 * 
 * @author ruoyi
 * @date 2024-12-19
 */
@RestController
@RequestMapping("/wasterTran/order")
public class TConstructionWasteTransportationOrderController extends BaseController
{
    @Autowired
    private ITConstructionWasteTransportationOrderService tConstructionWasteTransportationOrderService;

    /**
     * 查询建筑垃圾联运订单信息列表
     */
    @PreAuthorize("@ss.hasPermi('wasterTran:order:list')")
    @GetMapping("/list")
    public TableDataInfo list(TConstructionWasteTransportationOrder tConstructionWasteTransportationOrder)
    {
        SysUser user = getLoginUser().getUser();
        Long roleId = user.getRoleId();
        String roleKey = RolesEnums.getRoleKeyByRoleId(roleId);
        // 运输公司管理员
        if(RolesEnums.YUN_SHU_ADMIN.getRoleKey().equals(roleKey)){
            tConstructionWasteTransportationOrder.setTransportationCompanyId(user.getConstructionSiteCompanyId());
        }
        // 司机
        if(RolesEnums.DRIVER.getRoleKey().equals(roleKey)){
            tConstructionWasteTransportationOrder.setDriverUserId(user.getUserId());// 司机id
            tConstructionWasteTransportationOrder.setConstructionSiteCompanyId(user.getConstructionSiteCompanyId());// 运输公司id
        }

        startPage();
        List<TConstructionWasteTransportationOrder> list = tConstructionWasteTransportationOrderService.selectTConstructionWasteTransportationOrderList(tConstructionWasteTransportationOrder);
        return getDataTable(list);
    }

    /**
     * 导出建筑垃圾联运订单信息列表
     */
    @PreAuthorize("@ss.hasPermi('wasterTran:order:export')")
    @Log(title = "建筑垃圾联运订单信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TConstructionWasteTransportationOrder tConstructionWasteTransportationOrder)
    {
        List<TConstructionWasteTransportationOrder> list = tConstructionWasteTransportationOrderService.selectTConstructionWasteTransportationOrderList(tConstructionWasteTransportationOrder);
        ExcelUtil<TConstructionWasteTransportationOrder> util = new ExcelUtil<TConstructionWasteTransportationOrder>(TConstructionWasteTransportationOrder.class);
        util.exportExcel(response, list, "建筑垃圾联运订单信息数据");
    }

    /**
     * 获取建筑垃圾联运订单信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('wasterTran:order:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(tConstructionWasteTransportationOrderService.selectTConstructionWasteTransportationOrderById(id));
    }

    /**
     * 新增建筑垃圾联运订单信息
     */
    @PreAuthorize("@ss.hasPermi('wasterTran:order:add')")
    @Log(title = "建筑垃圾联运订单信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TConstructionWasteTransportationOrder tConstructionWasteTransportationOrder)
    {

        SysUser user = getLoginUser().getUser();
        Long roleId = user.getRoleId();
        String roleKey = RolesEnums.getRoleKeyByRoleId(roleId);
        // 运输公司管理员
        if(RolesEnums.YUN_SHU_ADMIN.getRoleKey().equals(roleKey)){
            tConstructionWasteTransportationOrder.setConstructionSiteCompanyId(user.getConstructionSiteCompanyId());
        }
        // 司机
        if(RolesEnums.DRIVER.getRoleKey().equals(roleKey)){
            tConstructionWasteTransportationOrder.setDriverUserId(user.getUserId());
        }
        tConstructionWasteTransportationOrder.setCreateBy(user.getUserName());
        return toAjax(tConstructionWasteTransportationOrderService.insertTConstructionWasteTransportationOrder(tConstructionWasteTransportationOrder));
    }

    /**
     * 修改建筑垃圾联运订单信息
     */
    @PreAuthorize("@ss.hasPermi('wasterTran:order:edit')")
    @Log(title = "建筑垃圾联运订单信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TConstructionWasteTransportationOrder tConstructionWasteTransportationOrder)
    {
        return toAjax(tConstructionWasteTransportationOrderService.updateTConstructionWasteTransportationOrder(tConstructionWasteTransportationOrder));
    }

    /**
     * 删除建筑垃圾联运订单信息
     */
    @PreAuthorize("@ss.hasPermi('wasterTran:order:remove')")
    @Log(title = "建筑垃圾联运订单信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tConstructionWasteTransportationOrderService.deleteTConstructionWasteTransportationOrderByIds(ids));
    }
}
